package com.open.redis.config;

import com.open.redis.config.util.RedisBloom;
import com.open.redis.config.util.RedisLock;
import com.open.redis.config.util.RedisUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;


/**
 * @author: codex
 * @Date: 2025/4/5 16:05
 * @Version: V1.0
 * @description: |
 */

@Configuration
public class RedisConfig {

    @Bean
    @ConditionalOnMissingBean
    public RedisLock redisLock(){
        return new RedisLock();
    }
    @Bean
    public RedisBloom redisBloom(){
        return new RedisBloom();
    }
    @Bean
    public RedisUtil redisUtil(){
        return new RedisUtil();
    }

    @Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
        RedisSerializer<String> redisSerializer = new StringRedisSerializer();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        //key序列化
        redisTemplate.setKeySerializer(redisSerializer);
        //value序列化
        redisTemplate.setValueSerializer(redisSerializer);
        //value hashmap序列化
        redisTemplate.setHashKeySerializer(redisSerializer);
        //key hashmap序列化
        redisTemplate.setHashValueSerializer(redisSerializer);
        return redisTemplate;
    }
}
